﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NCS_CS
{
    public partial class VstatusButton : UserControl
    {
        private int m_n;
        private Label[] m_status;
        private bool[] m_value;
        public void setNstatus(int n)
        {
            m_n = n;
            m_status = new Label[m_n];
            m_value = new bool[m_n];
            this.tableLayoutPanel1.Controls.Clear();
            this.tableLayoutPanel1.RowCount = m_n;
            //this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
            for(int i=0;i<m_n;i++)
            {
                m_value[i] = true;
                m_status[i] = new Label();
                m_status[i].Text = i.ToString()+":"+m_value[i].ToString();
                this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
                this.tableLayoutPanel1.Controls.Add(m_status[i],0,i);
                m_status[i].Dock=DockStyle.Fill  ;
                m_status[i].DoubleClick += VstatusLabel_doubleClick;
                m_status[i].Click += VstatusLabel_Click;
            }
           
        }
        private void VstatusLabel_doubleClick(object sender, EventArgs e)
        {
            int i;
            Label l = (Label)sender;
            string s = l.Text;
            i = (int)Conversion.Val(s.Split(':')[0]);
            System.Windows.Forms.ColorDialog d=new ColorDialog();
            DialogResult r=d.ShowDialog();
            if (r != DialogResult.Abort)
            {
                l.BackColor = d.Color;
            }
        }
        private void VstatusLabel_Click(object sender, EventArgs e)
        {
            int i;
            Label l = (Label)sender;
            string s=l.Text ;
            i=(int)Conversion.Val( s.Split(':')[0]);
            m_value[i]=!m_value[i];
            l.Text = i.ToString() + ":" + m_value[i].ToString();
        }
        public VstatusButton()
        {
            InitializeComponent();
        }

        private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
